package com.google.code.swingonfire.component.clock;

import java.lang.reflect.InvocationTargetException;

import com.google.code.swingonfire.builder.AbstractJComponentBuilder;

public class JClockBuilder extends AbstractJComponentBuilder<JClockBuilder, JClock>
{

    private JClockModel model;
    private Boolean editable;

    public JClockBuilder()
    {
        super(JClock.class);
    }

    public JClockBuilder(JClockModel model)
    {
        super(JClock.class);

        model(model);
    }

    public JClockBuilder model(JClockModel model)
    {
        this.model = model;

        return this;
    }

    public JClockBuilder editable(boolean editable)
    {
        this.editable = Boolean.valueOf(editable);

        return this;
    }

    @Override
    protected JClock newInstance(Class<JClock> type) throws InstantiationException, IllegalAccessException,
        IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException
    {
        if (model != null)
        {
            return type.getConstructor(JClockModel.class).newInstance(model);
        }

        return type.newInstance();
    }

    @Override
    protected void populate(JClock component)
    {
        if (editable != null)
        {
            component.setEditable(editable.booleanValue());
        }

        super.populate(component);
    }

}
